﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Weazel.NativeMath;

#endregion

namespace Weazel.NativeMath.Test
{
	[TestClass]
	public class TestXor
	{
		[TestMethod]
		public void TestXOR_1()
		{
			Integer a = new Integer(8, "0b00000000", false);
			Integer b = new Integer(8, "0b11111111", false);
			Integer r = new Integer(8, false);

			Assert.AreEqual("11111111", (a ^ b).ToBinaryString());

			Integer.Xor(r, a, b);
			Assert.AreEqual("11111111", r.ToBinaryString());
		}

		[TestMethod]
		public void TestXOR_2()
		{
			Integer a = new Integer(8, "0b11110000", false);
			Integer b = new Integer(8, "0b11111111", false);
			Integer r = new Integer(8, false);

			Assert.AreEqual("00001111", (a ^ b).ToBinaryString());

			Integer.Xor(r, a, b);
			Assert.AreEqual("00001111", r.ToBinaryString());
		}

		[TestMethod]
		public void TestXOR_3()
		{
			Integer a = new Integer(32, "0xFFFFFFFF", false);
			Integer b = new Integer(8, "0xFF", false);
			Integer r = new Integer(32, false);

			Assert.AreEqual("ffffff00", (a ^ b).ToHexadecimalString());

			Integer.Xor(r, a, b);
			Assert.AreEqual("ffffff00", r.ToHexadecimalString());
		}

		[TestMethod]
		public void TestXOR_4()
		{
			Integer b = new Integer(64, "0xFFFFFFFFFFFFFFFF", false);
			Integer a = new Integer(8, "0xFF", false);
			Integer r = new Integer(64, false);

			Assert.AreEqual("ffffffffffffff00", (a ^ b).ToHexadecimalString());

			Integer.Xor(r, a, b);
			Assert.AreEqual("ffffffffffffff00", r.ToHexadecimalString());
		}

		[TestMethod]
		public void TestXOR_5()
		{
			Integer b = new Integer(64, "0x0F0F0F0F0F0F0F0F", false);
			Integer a = new Integer(64, "0xFFFFFFFFFFFFFFFF", false);
			Integer r = new Integer(32, false);

			Assert.AreEqual("f0f0f0f0f0f0f0f0", (a ^ b).ToHexadecimalString());

			Integer.Xor(r, a, b);
			Assert.AreEqual("f0f0f0f0", r.ToHexadecimalString());
		}

		[TestMethod]
		public void TestXor_SingleBit1()
		{
			Integer a = new Integer(1, "0", false);
			Integer b = new Integer(1, "1", false);
			Integer r = new Integer(1, false);

			Assert.AreEqual("1", (a ^ b).ToHexadecimalString());

			Integer.Xor(r, a, b);
			Assert.AreEqual("1", r.ToHexadecimalString());
		}

		[TestMethod]
		public void TestXor_SingleBit2()
		{
			Integer a = new Integer(1, "1", false);
			Integer b = new Integer(1, "1", false);
			Integer r = new Integer(1, false);

			Assert.AreEqual("0", (a ^ b).ToHexadecimalString());

			Integer.Xor(r, a, b);
			Assert.AreEqual("0", r.ToHexadecimalString());
		}

		[TestMethod]
		public void TestXor_SingleBit3()
		{
			Integer a = new Integer(1, "0", false);
			Integer b = new Integer(1, "0", false);
			Integer r = new Integer(1, false);

			Assert.AreEqual("0", (a ^ b).ToHexadecimalString());

			Integer.Xor(r, a, b);
			Assert.AreEqual("0", r.ToHexadecimalString());
		}

	}
}
